In [31]:
from PIL import Image
import pytesseract
import googlemaps
import gmaps as jupmap
import sys
from datetime import datetime
# get my private keys for google maps and gmaps
f = open('private.key', 'r')
for line in f:
temp = line.rstrip('').replace(',','').replace('\n','').split(" ")
exec(temp[0])
myMap = googlemaps.Client(key=googlemap_key)
jupmap.configure(api_key=jupmap_key)
In [27]:
img = Image.open('mm_address.jpg')
label = pytesseract.image_to_string(img)
print(label)
clientLocation = label.splitlines()[2] + ', ' + label.splitlines()[3]
print(clientLocation)
testLocation = '2403 Englewood Ave, Durham, NC 27705'
print(testLocation)
In [28]:
testGeoCode = myMap.geocode(testLocation)[0]
lat = testGeoCode.get('geometry').get('location').get('lat')
lng = testGeoCode.get('geometry').get('location').get('lng')
print(lat, ' ', lng )
clientList = ['300 N Roxboro St, Durham, NC 27701','911 W Cornwallis Rd, Durham, NC 27707', '345 W Main Street, Durham, NC 27701' ]
wp=[]
for x in clientList:
testGeoCode = myMap.geocode(x)[0]
lat = testGeoCode.get('geometry').get('location').get('lat')
lng = testGeoCode.get('geometry').get('location').get('lng')
wp.append([lat,lng])
print(wp)
This api does not have a waypoint optimization Here are more details on how to do it: https://developers.google.com/maps/documentation/directions/intro
In [29]:
m = jupmap.Map()
home = (36.0160282, -78.9321707)
foodLion = (36.0193147,-78.9603636)
church = (35.9969749, -78.9091543)
dl = jupmap.directions_layer(church, home, waypoints=wp)
#googlemaps has an optimize_waypoints=True but I can't find it in jupyter gmaps
m.add_layer(dl)
m
In [ ]: